<?php
/* Frying Pan 
----------------------------------
   Version 0.2
   Needlworks (http://www.needlworks.org)
   Tatter Network Foundation ( http://forum.tattersite.com/ko ) / Textcube (http://www.textcube.org) 

   Creator          : inureyes
   Maintainer       : inureyes, daybreaker

   Created at       : 2008.3.13
   Last modified at : 2008.5.27

 General Public License
 http://www.gnu.org/licenses/gpl.html

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

*/

function FryingPan_oil($data) {
	global $database;
	requireModel('blog.comment');
	requireModel('blog.trackback');
	$limit_count = 500;
	set_time_limit(0);

	// Searching and deleting Every comment data.
	$cntPatn = FryingPan_cntPattern();
	$sql_src = " FROM {$database['prefix']}Comments ";
	$remaining = DBQuery::queryCell("SELECT COUNT(*) $sql_src", 0, false);
	$loop_count = 0;
	#syslog(LOG_USER, 'remaining comments '.$remaining);
	while ($remaining > 0) {
		$comments = DBQuery::queryAllWithoutCache("SELECT blogid, id, entry, name $sql_src LIMIT ".($loop_count * $limit_count).", $limit_count");
		if ($comments == null)
			break;
		$checked = 0;
		$trashed = 0;
		foreach($comments as $comment) {
			$checked++;
			$query = new TableQuery($database['prefix'].'Comments');
			$query->setQualifier('isFiltered', 0);
			$query->setQualifier('blogid', $comment['blogid']);
			$query->setQualifier('id', $comment['id']);
			$data = $query->getRow('homepage,comment');
			if ((preg_match('@http://[^/]*(hot|wet)[^/]*(women|girl)[^/]*2008[^/]*(com|net)@',$data['homepage']) > 0)) {
				trashComment($comment['blogid'], $comment['id'], $comment['entry'],null);
				$trashed ++;
			} else if (preg_match('/^[\\x{00}-\\x{7F}]+$/u',$comment['name'])) {
				foreach($cntPatn as $content) {
					if (stristr($data['comment'],$content)!==false) {
						trashComment($comment['blogid'], $comment['id'], $comment['entry'],null);
						$trashed ++;
						break;
					}
				}
			}
			unset($data);
			unset($query);
		}
		#syslog(LOG_USER, 'comment checked '.$checked.'/'.count($comments).', trashed '.$trashed.' in rage of ['.($loop_count * $limit_count).','.$limit_count.']');
		$remaining -= count($comments);
		$loop_count++;
	}
	// Searching and deleting every trackback data.
	$sql_src = " FROM {$database['prefix']}Trackbacks ";
	$remaining = DBQuery::queryCell("SELECT COUNT(*) $sql_src", 0, false);
	$loop_count = 0;
	#syslog(LOG_USER, 'remaining trackbacks '.$remaining);
	while ($remaining > 0) {
		$trackbacks = DBQuery::queryAllWithoutCache("SELECT blogid, id, entry, site $sql_src LIMIT ".($loop_count * $limit_count).", $limit_count");
		if ($trackbacks == null)
			break;
		foreach($trackbacks as $trackback) {
			$query = new TableQuery($database['prefix'] . 'Trackbacks');
			$query->setQualifier('isFiltered', 0);
			$query->setQualifier('blogid', $trackback['blogid']);
			$query->setQualifier('id', $trackback['id']);
			$data = $query->getRow('url,excerpt');
			if (preg_match('@http://[^/]*(hot|wet)[^/]*(women|girl)[^/]*2008[^/]*(com|net)@',$data['url']) > 0)
				trashTrackback($trackback['blogid'], $trackback['id']);
			else if (preg_match('/^[\\x{00}-\\x{7F}]+$/u',$trackback['site'])) {
				foreach($cntPatn as $content) {
					if (stristr($data['excerpt'],$content)!==false) {
						trashTrackback($trackback['blogid'], $trackback['id']);
						break;
					}
				}
			}
			unset($data);
			unset($query);
		}
		#syslog(LOG_USER, 'trackback checked '.$checked.', trashed '.$trashed.' in rage of ['.($loop_count * $limit_count).','.$limit_count.']');
		$remaining -= count($trackbacks);
		$loop_count++;
	}
	return true;
}

function FryingPan_cake($target, $mother) {
	return $target;
}

function FryingPan_cntPattern() {
	$pattern = array(
			'너가 좋을',
			'같지 않는',
			'동일할 지점',
			'걸출한 뉴스!',
			'걸출한 블로그!',
			'걸출한 위치!',
			'걸출한 디자인!',
			'그런 위치를',
			'경이롭 위해',
			'많게의 감사!',
			'나의 너의 친구는 위치의',
			'나는 합의한다',
			'너에 이다.',
			'나는 배웠다 매우',
			'우수한 있는다!',
			'웹사이트가 있는다!',
			'좋은 위치가 있는다!',
			'너는 위치를',
			'차가운 만들었다!',
			'너의 방문한 위치를 즐기는',
			'위한 감사합니다',
			'많은 감사 위치',
			'우수한 나는 너의',
			'그것을 감사 좋아한다',
			'좋은 아주 위치',
			'여기 이것은 뉴스',
			'우수한과 아주 도움',
			'우수한 위치!',
			'우수한 디자인!',
			'좋은 디자인.',
			'위치에 그것을',
			'유익한 뿐',
			'재미있는다',
			'우수한 감사!',
			'유용한 위치!',
			'유용한 정보!',
			'찾아본 그것 즐겼다!',
			'좋은 너를 위치',
			'걸출한 영역',
			'재미있는 아주',
			'역사는 이었다',
			'정보를 위한 감사합니다.',
			'정말 같지 않는 블로그',
			'중대한 축하',
			'경이롭 위치',
			'위치의 너의 현재 팬이',
			'현재 위치의 팬이 되었다');
	return $pattern;
}
?>
